package com.alingrad.android.froyoengine.input;

import javax.microedition.khronos.opengles.GL10;

import android.view.KeyEvent;
import android.view.MotionEvent;

import com.alingrad.android.froyoengine.tree.TreeNode;

public class InputManager extends TreeNode {
	private InputState mCurrentState;
	private InputState mActiveState;

	public InputManager() {
		super();
		mCurrentState = new InputState();
		mActiveState = new InputState();
	}
	
	
	@Override
	public void update(long delta) {
		synchronized(this) {
			mCurrentState.copy(mActiveState);
		}
	}


	public boolean isKeyDown(int keyCode) {
		return mCurrentState.isKeyDown(keyCode);
	}
	
	public TouchState getTouchState(int index) {
		return mCurrentState.getTouchState(index);
	}
	
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		synchronized(this) {
			return mActiveState.onKeyDown(keyCode, event);
		}
	}
	
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		synchronized(this) {
			return mActiveState.onKeyUp(keyCode, event);
		}
	}
	
	public boolean onTouchEvent(MotionEvent event) {
		synchronized(this) {
			return mActiveState.onTouchEvent(event);
		}
	}

	@Override
	public void load(GL10 gl) {
	}


	@Override
	public boolean isAlive() {
		return true;
	}
	
}
